﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using CCWin;

namespace WinFromBook
{
    public partial class FrmMain : CCSkinMain
    {
        public FrmMain()
        {
            InitializeComponent();
        }
        public string AdminName { get; set; }//存储管理员名称
        public int limits { get; set; }//存储管理员权限
        FrmAnsAdminInfo FA;
        /// <summary>
        /// 设置子窗体唯一
        /// </summary>
        /// <param name="childFrmName">子窗体名称</param>
        private void checkChildFrmExist(string childFrmName)//参数窗体名称
        {
            foreach (Form Check in this.MdiChildren)
            {
                if (Check.Name == childFrmName)
                {
                    Check.Visible = true;
                    Check.Activate();
                    return;
                }
            }
        }
        DateTime dt = new DateTime();
        private void FrmMain_Load(object sender, EventArgs e)
        {

            this.AdminTool.Text = "管理权限：超级管理员";
            if (limits == 2)
            {
                this.账号注册ToolStripMenuItem.Enabled = false;
                this.AdminTool.Text = "管理权限：普通管理员";
            }
            this.LastStrip.Text = "管理员：" + AdminName;
            //开启时间控件
            this.Timer.Enabled = true;
            int n = (int)dt.DayOfWeek;
            string[] weekDays = { "星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };

            //获取当前时间 
            this.DataTimeTool.Text = "当前时间：" + DateTime.Now.ToLongDateString() + " , " + weekDays[n] + " , " + DateTime.Now.ToLongTimeString();
           //窗体最大化
            this.WindowState=FormWindowState.Maximized;
        
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            int n = (int)dt.DayOfWeek;
            string[] weekDays = { "星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };

            //获取当前时间 
            this.DataTimeTool.Text = "当前时间：" + DateTime.Now.ToLongDateString() + " , " + weekDays[n] + " , " + DateTime.Now.ToLongTimeString();
        }

        private void 账号查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FA = new FrmAnsAdminInfo();
            if (this.AdminTool.Text != "管理权限：超级管理员")
            {
                FA.limits = "普通管理员";
            }
            FA.AName = AdminName;
            FA.MdiParent = this;
            checkChildFrmExist(FA.Name);
        }

        private void 账号注册ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmRegister FR = new FrmRegister();
            FR.MdiParent = this;
            FR.FAI = FA;
            checkChildFrmExist(FR.Name);
        }

        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            //关闭整个程序
            Application.Exit();
        }

        private void 切换账号ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("确认切换用户么？", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (dr == DialogResult.OK)
            {
                this.Hide();
                FrmLoad FL = new FrmLoad();
                FL.Show();
            }
        }

        private void 退出登录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("确认退出系统？", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (dr == DialogResult.OK)
            {
                Application.Exit();
            }
        }

        private void 查询所有图书ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmBookInfo Fb = new FrmBookInfo();
            Fb.MdiParent = this;
            checkChildFrmExist(Fb.Name);
        }

        private void 图书状态ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmBookState fbs = new FrmBookState();
            fbs.MdiParent = this;
            checkChildFrmExist(fbs.Name);
        }

        private void 新书入库ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmBookInsert fb = new FrmBookInsert();
            fb.MdiParent = this;
            checkChildFrmExist(fb.Name);
        }

        private void 借书登记ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmBorrwer fb = new FrmBorrwer();
            fb.MdiParent = this;
            fb.Text = "借阅登记";
            checkChildFrmExist(fb.Name);
        }

        private void 读者借书证办理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmReaderID fr = new FrmReaderID();
            fr.MdiParent = this;
            checkChildFrmExist(fr.Name);
        }

        private void 读者赔偿记录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmReaderInfo fr = new FrmReaderInfo();
            fr.MdiParent = this;
            checkChildFrmExist(fr.Name);
        }

        private void 读者借书证注销ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmReadInfodrop Ri = new FrmReadInfodrop();
            Ri.MdiParent = this;
            checkChildFrmExist(Ri.Name);
        }

        private void 借阅记录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmBorrowhistory FB = new FrmBorrowhistory();
            FB.MdiParent = this;
            checkChildFrmExist(FB.Name);
        }

        private void 图书类型ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmTypeInfo Ft = new FrmTypeInfo();
            Ft.MdiParent = this;
            checkChildFrmExist(Ft.Name);
        }

        private void 书架管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmReading Fr = new FrmReading();
            Fr.MdiParent = this;
            checkChildFrmExist(Fr.Name);
        }

        private void 关于ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            frmAbout Fr = new frmAbout();
            Fr.MdiParent = this;
            checkChildFrmExist(Fr.Name);
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            FrmBookInfo Fb = new FrmBookInfo();
            Fb.MdiParent = this;
            checkChildFrmExist(Fb.Name);
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            FrmReadInfodrop fr = new FrmReadInfodrop();
            fr.MdiParent = this;
            checkChildFrmExist(fr.Name);
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            FrmBorrowhistory FB = new FrmBorrowhistory();
            FB.MdiParent = this;
            checkChildFrmExist(FB.Name);
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            FrmBorrwer fb = new FrmBorrwer();
            fb.MdiParent = this;
            fb.Text = "借阅登记";
            checkChildFrmExist(fb.Name);
        }

        
       
    }
}
